<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号">
              <j-input placeholder="请输入单据编号" v-model="queryParam.billNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="回款公司">
              <select-Company-input  v-model="queryParam.payeeUnit"   multi/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属团队">
              <select-team-input v-model="queryParam.busiTeamId" :teamType="0" :tdlx="3" multi/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目名称">
              <select-project-input v-model="queryParam.projectId" :projectStatus="'2'" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="购买方单位名称">
              <select-customer-input placeholder="请选择购买方单位名称" v-model="queryParam.remittanceUnit" commercialType="1" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="业主单位">
              <select-customer-input placeholder="请选择业主单位" v-model="queryParam.ownerUnit" commercialType="1" />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="回款金额">
              <a-input-number placeholder="请输入最小值" class="query-group-cust" :precision="0" v-model="queryParam.remittanceAmount_begin" style="width:calc(50% - 15px);"></a-input-number>
              <span class="query-group-split-cust"></span>
              <a-input-number placeholder="请输入最大值" class="query-group-cust" :precision="0" :min="queryParam.remittanceAmount_begin" v-model="queryParam.remittanceAmount_end" style="width:calc(50% - 15px);"></a-input-number>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="CBS银行流水号">
              <j-input placeholder="请输入CBS银行流水号" v-model="queryParam.bankTransNo"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="流程状态">
              <j-dict-select-tag type="list" v-model="queryParam.bpmStatus" dictCode="bpm_status" placeholder="请选择流程状态"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="回款时间">
              <a-range-picker v-model="remittanceDate" :allowClear="false"
                                format="YYYY-MM-DD"
                                :placeholder="['开始时间', '结束时间']"
                                @change="onCreateTimeChange" />
              </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="remittanceDate=[],searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('回款认领台账汇总表')" :disabled="isDisabledAuth('erpFinanceTeamManager:export')">导出</a-button>
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in columns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:scrollX}"
        :components="draggableComponent"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        :customRow="customRow"
        @change="handleTableChange">
        <a slot="projectId" slot-scope="text, record" @click="onDetail(record.projectId)">{{ text }}</a>
        <a slot="remittanceAmount" slot-scope="text, record" @click="onAmountDetail(record.billId)">{{ text }}</a>
       <!-- <a slot="projectFinalNo" slot-scope="text, record" @click="getDetail(record.id)">{{ text }}</a> -->
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
      </a-table>
    </div>
    <!-- 项目详情开始 -->
    <erp-project-report-modal  ref="projectReport"></erp-project-report-modal>
    <ErpFinanceCollectMoneyBillPenetrate ref="collectMoneyBill"></ErpFinanceCollectMoneyBillPenetrate>
    <!-- 项目详情结束 -->
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { httpAction, getAction } from '@/api/manage'
  import { mixinDevice } from '@/utils/mixin'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import moment from 'moment'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
  export default {
    name: 'ErpCollectContractReportSlipList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      SelectProjectInput,
      SelectCustomerInput,
      SelectCompanyInput,
      SelectTeamInput,
      ErpProjectReportModal:()=> import('@/views/erp/report/project/modules/ErpProjectReportModal'),
      ErpFinanceCollectMoneyBillPenetrate:()=> import('@/views/scy/penetrate/ErpFinanceCollectMoneyBillPenetrate')
    },
    data () {
      return {
        remittanceDate:[moment().startOf('year').format('YYYY-MM-DD'),moment(new Date()).format('YYYY-MM-DD')],
        queryParam:{
          remittanceDate_begin:moment().startOf('year').format('YYYY-MM-DD'),
          remittanceDate_end:moment(new Date()).format('YYYY-MM-DD')
        },
        createTimeRange:[],
        description: '回款认领台账',
        columns:[],
        //表头
        defColumns:[
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'回款公司',
            align:"center",
            dataIndex: 'payeeUnit_dictText',
            ellipsis: true,
            width:137,
          },
          {
            title:'回款时间',
            align:"center",
            dataIndex: 'remittanceDate',
            ellipsis: true,
            width:137,
          },
          {
            title:'购买方单位名称',
            align:"center",
            dataIndex: 'remittanceUnit_dictText',
            ellipsis: true,
            width:137,
          },
          {
            title:'单据编号',
            align:"center",
            dataIndex: 'billNo',
            ellipsis: true,
            width:137,
          },
          {
            title:'回款金额（元）',
            align:"center",
            dataIndex: 'remittanceAmount',
            scopedSlots: { customRender: 'remittanceAmount' },
            ellipsis: true,
            width:137,
          },
          {
            title:'回款方式',
            align:"center",
            dataIndex: 'payMode_dictText',
            ellipsis: true,
            width:137,
          },
          {
            title:'项目编号',
            align:"center",
            dataIndex: 'projectFinalNo',
            ellipsis: true,
            width:137,
          },
          {
            title:'项目名称',
            align:"center",
            dataIndex: 'projectName',
            scopedSlots: { customRender: 'projectId' },
            ellipsis: true,
            width:137,
          },
          {
            title:'业主单位',
            align:"center",
            dataIndex: 'ownerUnit_dictText',
            ellipsis: true,
            width:137,
          },
          {
            title:'合同金额（元）',
            align:"center",
            dataIndex: 'contractMoney',
            ellipsis: true,
            width:137,
          },
          {
            title:'所属年度',
            align:"center",
            dataIndex: 'projectYear_dictText',
            ellipsis: true,
            width:137,
          },
          {
            title:'所属团队',
            align:"center",
            dataIndex: 'busiTeamId_dictText',
            ellipsis: true,
            width:137,
          },
          {
            title:'流程状态',
            align:"center",
            dataIndex: 'bpmStatus_dictText',
            ellipsis: true,
            width:137,
          },
          {
            title:'CBS银行流水号',
            align:"center",
            dataIndex: 'bankTransNo',
            ellipsis: true,
            width:137,
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark',
            ellipsis: true,
            width:137,
          }
        ],
        /* 排序参数 */
        isorter: {
          column: 'updateTime',
          order: 'desc'
        },
        //列设置
        settingColumns:[],
        url: {
          queryProjectReportById: '/api/erp/project/report/erpProjectReport/queryById',
          list: "/api/erp/finance/report/erpCollectMoneyReport/list",
          exportXlsUrl: "/api/erp/finance/report/erpCollectMoneyReport/exportXls"
        },
        //代码生成后需手动设置流程编码
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      onAmountDetail(id){
        this.$refs.collectMoneyBill.initData(id);
        this.$refs.collectMoneyBill.visible = true;
      },
      onDetail(id) {
        const that = this
        this.$nextTick(() => {
          getAction(this.url.queryProjectReportById, { id }).then((res) => {
            if (res.success) {
              const model = res.result
              that.$refs.projectReport.getDetail(model);
              that.$refs.projectReport.title = '项目一览表';
            }
          })
        })
      },
      searchQuery() {
        this.onClearSelected();
        this.loadData(1)
      },
      onCreateTimeChange(dateString) {
        this.queryParam.remittanceDate_begin=moment(dateString[0]).format('YYYY-MM-DD')+" 00:00:00";
        this.queryParam.remittanceDate_end=moment(dateString[1]).format('YYYY-MM-DD')+" 23:59:59";
      },
      initDictConfig(){
      },
      searchReset() {
        this.queryParam = {
          remittanceDate_begin:moment().startOf('year').format('YYYY-MM-DD'),
          remittanceDate_end:moment(new Date()).format('YYYY-MM-DD')
        }
        this.remittanceDate=[moment().startOf('year').format('YYYY-MM-DD'),moment(new Date()).format('YYYY-MM-DD')]
        this.onClearSelected();
        this.loadData(1)
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'date',value:'createTime',text:'创建日期'})
        fieldList.push({type:'string',value:'handlerId',text:'经办人编号',dictCode:''})
        fieldList.push({type:'string',value:'handlerDeptId',text:'经办人部门ID',dictCode:''})
        fieldList.push({type:'string',value:'billNo',text:'单据编号',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'applicant',text:'申请公司',dictCode:''})
        fieldList.push({type:'string',value:'isRelContract',text:'是否关联合同',dictCode:'yes_no'})
        fieldList.push({type:'string',value:'payMode',text:'支付方式(字典)',dictCode:'payment_type'})
        fieldList.push({type:'string',value:'payeeName',text:'收款方名称',dictCode:''})
        fieldList.push({type:'string',value:'payeeBankName',text:'收款方开户行',dictCode:''})
        fieldList.push({type:'string',value:'payeeAccountNo',text:'收款方账户',dictCode:''})
        fieldList.push({type:'string',value:'payeeContacts',text:'收款联系人',dictCode:''})
        fieldList.push({type:'string',value:'payeeContactInfo',text:'收款联系方式',dictCode:''})
        fieldList.push({type:'string',value:'payRemark',text:'打款备注',dictCode:''})
        fieldList.push({type:'Text',value:'attachments',text:'附件',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
